package org.map
{
	import flash.display.MovieClip;

	public class Map
	{	
		//区块的大小
		public static var size:int
		//长方菱形的列数	 
		private static var cols:int
		//长方菱形的行数	 
		private static var rows:int
		
		public var tileTable:Array;
		public var dynamicTileTable:Array;
		public var projectileTileTable:Array;// Position of each long range attack
		
		public function Map()
		{
		}
		
		public static function init(_cols:int,_rows:int,_size:int):void{
			
			size=_size
			
			cols=_cols
			
			rows=_rows
			
		}
		
		
		//------ Build Map ------------------------------------
		function buildMap() {
				tileTable = new Array(rows);
				dynamicTileTable = new Array(rows);
				projectileTileTable = new Array(rows);
				for (var j=0; j<rows; ++j) {
					tileTable[j]=new Array(cols);
					dynamicTileTable[j]=new Array(cols);
					projectileTileTable[j]=new Array(cols);
					for (var i=0; i<cols; ++i) {
						tileTable[j][i]=1000;
						dynamicTileTable[j][i]=new Array();
						projectileTileTable[j][i]=new Array();
					}
				}
		}
		
		
		//----- Init World Tile -----------------------------------
		public function initWorldTile():void {
			var worldTile:Array = new Array(rows);
			for (var j=0; j<rows; j++) {
				worldTile[j]=new Array(rows);
				for (var i=0; i<cols; i++) {
					worldTile[j][i] = new MovieClip();
					var tile:MovieClip = worldTile[j][i];
					tile.x = i * 10 - j * 10;
					tile.y = (i * 10 + j * 10)/2;
					addTile(j,i,-1);
				}
			}
		}
		
		//----- Add Tile -----------------------------------
		public function addTile(j:Number,i:Number,index:Number) :MovieClip{
			var tile:MovieClip= worldTile[j][i];
			swapTile(j,i);
			tile.transform.colorTransform = new ColorTransform(game.map.R,game.map.G,game.map.B,1,0,0,0,0);
			if(index == -1){
				map.addChild(tile);
			}else{
				map.addChildAt(tile,index);
			}			
			return tile;
		}
		
	}
}